(function (vc, vm) {
    vc.extends({
        data: {
            returnFeeDetailInfo: {
                detailId: '',
                cycles: '',
                receivableAmount: '',
                receivedAmount: '',
                primeRate: '',
                remark: '',
                payTime: '',
                reason: '',
                communityId: '',
                feeId: '',
                feeTypeCd: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('returnPayFee', 'openReturnPayFeeModel', function (_params) {
                $that.refreshFeeDetailInfo();
                $that.pushReturnFeeDetailInfo(_params);
                $('#returnPayFeeModel').modal('show');
            });
        },
        methods: {
            refreshFeeDetailInfo: function () {
                $that.returnFeeDetailInfo = {
                    detailId: '',
                    cycles: '',
                    receivableAmount: '',
                    receivedAmount: '',
                    primeRate: '',
                    remark: '',
                    payTime: '',
                    reason: '',
                    communityId: '',
                    feeId: '',
                    feeTypeCd: '',
                    configId: ''
                }
            },
            pushReturnFeeDetailInfo: function (_params) {
                $that.returnFeeDetailInfo.communityId = _params.communityId;
                $that.returnFeeDetailInfo.payTime = _params.createTime;
                $that.returnFeeDetailInfo.detailId = _params.detailId;
                $that.returnFeeDetailInfo.cycles = _params.cycles;
                $that.returnFeeDetailInfo.receivableAmount = _params.receivableAmount;
                $that.returnFeeDetailInfo.receivedAmount = _params.receivedAmount;
                $that.returnFeeDetailInfo.primeRate = _params.primeRate;
                $that.returnFeeDetailInfo.feeId = _params.mainFeeInfo.feeId;
                $that.returnFeeDetailInfo.feeTypeCd = _params.mainFeeInfo.feeTypeCd;
                $that.returnFeeDetailInfo.remark = _params.remark;
                $that.returnFeeDetailInfo.configId = _params.mainFeeInfo.configId;
            },
            returnPayFeeValidate: function () {
                return vc.validate.validate({
                    returnFeeDetailInfo: $that.returnFeeDetailInfo
                }, {
                    'returnFeeDetailInfo.reason': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "退费原因不能为空"
                        },
                        {
                            limit: "maxin",
                            param: "1,200",
                            errInfo: "退费原因不能超过200位"
                        }
                    ]
                });
            },
            submitReturnPayFee: function () {
                if (!$that.returnPayFeeValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.returnFeeDetailInfo.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    '/returnPayFee.saveReturnPayFee',
                    JSON.stringify($that.returnFeeDetailInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            $('#returnPayFeeModel').modal('hide');
                            vc.emit('propertyFee', 'listFeeDetail', $that.returnFeeDetailInfo);
                            vc.emit('refundDepositFee', 'listFeeDeposit', $that.returnFeeDetailInfo);
                            
                            $that.refreshFeeDetailInfo();
                            vc.toast("操作成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        vc.toast(errInfo);
                    });
            }
        }
    });
})(window.vc, window.$that);
